package cn.singno.bob.solr.test.repository;

import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.solr.core.query.result.FacetPage;
import org.springframework.data.solr.core.query.result.HighlightPage;
import org.springframework.data.solr.repository.Boost;
import org.springframework.data.solr.repository.Facet;
import org.springframework.data.solr.repository.Highlight;
import org.springframework.data.solr.repository.Query;

import cn.singno.bob.solr.repository.BSSolrRepository;
import cn.singno.bob.solr.test.entity.User;

public interface UserRepository extends BSSolrRepository<User, String>{

	
	
	
	public User findByName(String name);			//方法命名查询
	
	@Query("id:*?0* or name:*?0*")
	public Page<User> find2(String name, Pageable page);		//分页中已经有排序可以添加，不能在方法中分页和排序同时使用
	
	@Query("name:*?0*")
	public Page<User> findSort(String name, Pageable page );
	
	@Query("name:*?0*")
	public Page<User>  findBoost(@Boost(2)String name, Pageable page);				//权重搜索(打分机制)，表示某个字段在搜索时优先于其他字段  
	
	@Query("name:*?0*")
	@Facet(fields = { "id" }, limit = 5)	//q=name:<name>&facet=true&facet.field=id&facet.limit=10										//精确查询, 搜索出条件后再搜索
	public FacetPage<User> findFacet(String name, Pageable page);					//面搜索
	
	@Query("name:*?0*")
	@Highlight(prefix = "<highlight>", postfix = "</highlight>")
	public HighlightPage<User> findHighlight(String name, Pageable pageable);
	
	
	//ScoredPage				打分机制分页
}
